﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Admin
{
    public partial class ListRewardJobs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["AdminLogin2"] != null)
                {
                    int atid = Convert.ToInt32(Session["AdminLogin2"]);
                    Bind(atid);
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='adminlogin2.aspx'");
                }
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_check")
            {
                if (e.CommandArgument != null)
                {

                    if (new lcmyjobs.BLL.enterprise_reward().UpdateWhere("releasetime", DateTime.Now.ToString(), e.CommandArgument.ToString()))
                    {
                        //Maticsoft.Common.MessageBox.Show(this, "刷新悬赏成功！");
                        if (Session["AdminLogin2"] != null)
                        {
                            int atid = Convert.ToInt32(Session["AdminLogin2"]);

                            Bind(atid);
                        }
                    }

                }
            }
        }
        //审核
        protected void lbn_update_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_reward().UpdateWhere("status", "1", idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "审核成功！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "请选择所要审核的单位！");
            }
        }
        //取消审核
        protected void lbn_cancle_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_reward().UpdateWhere("status", "2", idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "取消审核成功！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "请选择所要取消审核的单位！");
            }
        }
        //成功
        protected void lbn_issuccess_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_reward().UpdateWhere("issuccess", "1", idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "成功！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "请选择所要成功的职位！");
            }
        }
        //刷新悬赏
        protected void lbn_refresh_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();


            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_reward().UpdateWhere("releasetime", DateTime.Now.ToString(), idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "刷新悬赏成功！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "请选择所要刷新悬赏的职位！");
            }
        }
      

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["AdminLogin2"] != null)
            {
                int atid = Convert.ToInt32(Session["AdminLogin2"]);

                Bind(atid);
            }
        }

        private void Bind(int atid)
        {
            int count = 0;

            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetAllRewardJobdByAtid(atid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);

            if (ds.Tables[1].Rows.Count > 0)
            {
                this.lbl_count.Text = ds.Tables[1].Rows[0][0].ToString();
            }
           

            this.AspNetPager1.RecordCount = count;

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }


        /// <summary>
        /// 获取主键ID列表
        /// </summary>
        /// <returns></returns>
        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)this.GridView1.Rows[i].FindControl("cbo_rid");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
        public string GetBH(string str)
        {
            return "XZ" + str.ToString().PadLeft(6, '0');
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.Cells[7].Text == "&#215;")
            {
                e.Row.Cells[7].ControlStyle.ForeColor = System.Drawing.Color.Red;
            }
            if (e.Row.Cells[5].Text == "&#215;")
            {
                e.Row.Cells[5].ControlStyle.ForeColor = System.Drawing.Color.Red;
            }
        }

      
      
    

    }
}